package com.woniuxy.service.impl;

import com.woniuxy.common.Result;
import com.woniuxy.dao.UserMapper;
import com.woniuxy.entity.User;
import com.woniuxy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;
    /**
     * 登录的查询功能
     *
     * @param param
     */
    @Override
    public Result<User> login(User param) {
        //1.判断用户是否存在
        User user = userMapper.findByUserName(param.getUsername());
        if (user == null){
            return Result.fail("用户名不存在");
        }

        if(!param.getPassword().equals(user.getPassword())){
            return Result.fail("密码错误");
        }
        //2判断密码是否正确
        //        创建加密的对象
//        BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
//        //比较密码
//        boolean matches = encoder.matches(param.getPassword(), user.getPassword());
//        if (!matches){
//            return Result.fail("密码错误");
//        }

        //4登录成功
        return Result.success("登录成功",user);
    }
}
